package com.ljyh.cygnus.screens.viewmodel

import android.content.Context
import android.net.wifi.WifiConfiguration
import android.net.wifi.WifiManager
import android.util.Log
import com.ljyh.cygnus.model.CommandUiState
import com.ljyh.cygnus.utils.PolicyManager
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

class HotSpotViewModel : BaseViewModel() {
    private val _uiState = MutableStateFlow<CommandUiState>(CommandUiState.Idle)
    val uiState: StateFlow<CommandUiState> = _uiState.asStateFlow()

    fun enableHotSpot() {
        executeRootCommands(
            _uiState,
            "iptables -D FORWARD -j DROP || true",
            "iptables -D FORWARD -j ACCEPT || true"
        )
    }

    fun disableHotSpot(shouldRestore: Boolean) {
        if (shouldRestore) {
            executeRootCommands(_uiState, "svc wifi disable","sleep 1","svc wifi enable")
        } else {
            executeRootCommands(_uiState,"svc wifi disable")
        }


    }


    fun restrictionHotSpot() {
        executeRootCommands(
            _uiState,
            "iptables -D FORWARD -j DROP || true",
            "iptables -D FORWARD -j ACCEPT || true",
            // 插入一条最高优先级的 DROP 规则到 FORWARD 链，阻止所有流量转发
            "iptables -I FORWARD 1 -j DROP"
        )
    }



}